home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
TeX 1995 July
/
TeX CD-ROM July 1995 (Disc 1)(Walnut Creek)(1995).ISO
/
web
/
fweb
/
fweb-1.40
/
manual
/
demo4.web
< prev
next >
Wrap
Text File
|
1993-10-29
|
2KB
|
62 lines
@z --- demo4.web ---
This file is included in fwebman.tex.
Author: J. A. Krommes
Version: 1.23
Date: May 27, 1992
@x-----------------------------------------------------------------------------
@n/[-W[]
@* ARRAY PROCESSING. This example demonstrates two ways of beautifying
array references in \Fortran\ and~C. Parenthesized references can be
overloaded with the `\.{@@W}'~command, as follows:
@W x . // Replace references to~\Wshort{x} by the macro~\.{\\x}.
@W y .
@W z .
@l "\\def\\x(#1){x^{#1}}" // Contravariant index.
@l "\\def\\y(#1){y_{#1}}" // Covariant index.
@l "\\def\\z(#1,#2){z^{#1}{}_{#2}}" // Mixed indices.
@ Bracketed array references are activated by the `\.{-W[}'~command.
(In \Fortran\ \FTANGLE\ always automatically replaces brackets by
parentheses.) One can redefine the \.{\\WARRAY} macro to get special effects.
@l "\\let\\WARRAY\\WSUB" /* Subscript bracketed indices. (\.{\\WSUB}~is
defined in \.{fwebmac.web}.) */
@ In the following test, carefully note the difference in type size between
the results of parenthesized subscripts and bracketed ones. To fully
understand why this occurs, study the definition of the \.{\\WXA}~macro in
\.{fwebmac.web}.
@a
program main
@e
/* Test of overloaded identifiers. */
x(i)
y(j)
z(i,j)
/* Bracketed indexing. */
A[i]
B[j_par]
C[index,j_par]
D[index[j_par+1]]
E[1+2*i]
/* Brackets aren't active inside strings. */
'a[b]c(d)'
end
@c
/* Now, an example from C. */
a[1][2][k]; // In the source, this is ``\.{a[1][2][k]}''.
@* INDEX.